<%--
  Created by IntelliJ IDEA.
  User: 步步为莹
  Date: 2019/9/17
  Time: 9:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Beyond车辆管理平台</title>
    <link rel="stylesheet" href="../../../static/css/style.css">
    <link rel="stylesheet" href="../../../static/css/jquery.wysiwyg.old-school.css">
    
    <!-- jQuery AND jQueryUI -->
    <script type="text/javascript" src="../../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../../static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../../static/js/min.js"></script>
    <!--<script type="text/javascript" src="js/index.js"></script>-->
</head>
<body>
<script type="text/javascript" src="../../../static/js/main.js"></script>
<link rel="stylesheet" href="../../../static/css/style2.css">
<div id="content" class="white">
    <h1><img src="../../../static/images/users1.png" alt="">菜单管理</h1>
    <div class="bloc">
        <div class="title"> 操作 <a class="toggle"></a></div>
        <div class="content dashboard">
            <div class="center" style="display: block; width: auto;">
                <a href="javascript:;" onclick="add()">新增菜单</a>
                <a href="javascript:;">
                    批量删除 </a>
            </div>
        </div>
    </div>
    <div class="bloc">
        <div class="title">菜单列表</div>
        <div class="content">
            <table>
                <thead>
                <tr>
                    <th><input type="checkbox" id="selectALL" onclick="selectAll(this)">全选</th>
                    <th>序号</th>
                    <th>菜单名称</th>
                    <th>菜单类型</th>
                    <th>菜单路径</th>
                    <th>备注</th>
                </tr>
                </thead>
                <tbody id="listMenu">
                
                </tbody>
            </table>
    
        </div>
    </div>
</div>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
<script type="text/javascript">
    //加载角色列表
    loadMenulist(1);
    function loadMenulist(page){
    $("tbody#listMenu").html("");
    $.ajax({
    url:"<%=request.getContextPath()%>/menuServlet",
    type:"GET",
    data:"opr=listMenu&startRow="+(page-1)*7+"&pageSize=7",
    dataType:"json",
    success:function (result) {
    console.log(result);
    var stuUser="";
    $.each(result[1],function (index,ele) {
    stuUser+="<tr >";
    stuUser+="<td><input type='checkbox' class='UserId'><input type='hidden' value='"+ele.id+"'> </td>"
    stuUser+="<td>"+ele.order_num+"</td>";
    stuUser+="<td>"+ele.name+"</td>";
    stuUser+="<td>"+ele.menu_type+"</td>";
    stuUser+="<td>"+ele.uRL+"</td>";
    stuUser+="<td>"+ele.remark+"</td>";
    stuUser+="<td><a href='javascript:;' title='修改' onclick='update(this)'>\n" +
    "<img src='../../../static/images/edit.png'></a>\n" +
    "<a href='javascript:;' title='删除' onclick='del(this)'>\n" +
    "<img src='../../../static/images/delete.png'></a></td>";
    stuUser+="</tr>";
    });
    var pageStr="";
    if (result[0][1]>0){
    
    if (page == 1) {
    pageStr += "<tr>";
    pageStr +=
    "<td><a href='javascript:;' onclick='loadMenulist(" + eval(parseInt(page) + 1) + ")'>下一页</a></td>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(" +
    result[0][1] + ")'>末页</a></td>";
    } else if (page == result[0][1]) {
    pageStr += "<tr>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(1)'>首页</a></td>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(" + eval(page - 1) + ")'>上一页</a></td>";
    } else if (page > 1 && page < result[0][1]) {
    pageStr += "<tr>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(1)'>首页</a></td>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(" + eval(page - 1) + ")'>上一页</a></td>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(" + eval(parseInt(page) + 1) + ")'>下一页</a></td>";
    pageStr += "<td><a href='javascript:;' onclick='loadMenulist(" + result[0][1] + ")'>尾页</a></td>";
    }
    pageStr += "</tr><tr>"
    pageStr += "<td>总记录数" + result[0][0] + "条</td><td>每页7条</td>";
    pageStr += "<td>页数" + page + "/" + result[0][1] + "页</td>";
    pageStr += "</tr>";
    }
    $("tbody#listMenu").append(stuUser);
    $("tbody#listMenu").append(pageStr);
    }
    });
  
    }

    /**
     * 删除菜单
     * @param obj
     */
    function  del(obj) {
        var menuId=$(obj).parent().siblings("td").children("[type='hidden']").val();
        var confirm=window.confirm("确定删除吗？")
        if (confirm===true){
            $.ajax({
                url:"<%=request.getContextPath()%>/menuServlet",
                data:"Id="+menuId+"&opr=deleteMenu",
                dataType:"text",
                type:"GET",
                success:function (result) {
                    console.log(result)
                    if (result=='true'){
                        alert("删除成功！");
                        window.location.reload();
                    }else {
                        alert("删除失败！");
                    }
                }
            })
        }
    }
//更改菜单
    function update(obj) {
        var menuId=$(obj).parent().siblings("td").children("[type='hidden']").val();
        window.location.href="menuUpdate.jsp?id="+menuId;
    }

    //其他复选框取消选中时全选取消
    function checkFalse(obj){
        if(!$(this).is(":checked")){
            $("#selectALL").prop("checked",false);
        }
    }

    //全选
    function selectAll(obj){
        //prop() 方法设置或返回被选元素的属性和值
        if($(obj).is(':checked')){
            $(":checkbox").prop("checked",true);
        }else {
            $(":checkbox").prop("checked",false);
        }
    };
</script>

</body>
</html>
